package dissertation.examples.ejb11.entity;

import javax.ejb.*;

public class ProductBean implements EntityBean {
    protected EntityContext ctx;
    public String name;
    public double price;
    public String productId;

    public ProductBean() {
        System.out.println("New Product Entity Bean instance created by the EJB Container");
    }

    @Override
    public String getName() {
        System.out.println("getName()");
        return name;
    }

    @Override
    public void setName(String name) {
        System.out.println("setName()");
        this.name = name;
    }

    @Override
    public double getPrice() {
        System.out.println("getPrice()");
        return price;
    }

    @Override
    public void setPrice(double price) {
        System.out.println("setPrice()");
        this.price = price;
    }

    @Override
    public String getProductId() {
        System.out.println("getProductId()");
        return productId;
    }

    public void setEntityContext(EntityContext entityContext) throws EJBException {
        System.out.println("setEntityContext()");
        ctx = entityContext;
    }

    public void unsetEntityContext() throws EJBException {
        System.out.println("unsetEntityContext()");
        ctx = null;
    }

    public void ejbRemove() throws RemoveException, EJBException {
        System.out.println("ejbRemove()");
    }

    public void ejbActivate() throws EJBException {
        System.out.println("ejbActivate()");
    }

    public void ejbPassivate() throws EJBException {
        System.out.println("ejbPassivate()");
    }

    public void ejbLoad() throws EJBException {
        System.out.println("ejbLoad()");
    }

    public void ejbStore() throws EJBException {
        System.out.println("ejbStore()");
    }

    @Override
    public ProductPK ejbCreate(String productId, String name, double price) throws CreateException {
        System.out.println("ejbCreate(" + productId + ", " + name + ", " + price + ")");
        this.productId = productId;
        this.name = name;
        this.price = price;
        return new ProductPK(productId);
    }

    @Override
    public void ejbPostCreate(String productId, String name, double price) throws CreateException {
        System.out.println("ejbPostCreate()");
    }
}
